//
//  HMVisitorView.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/9.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMVisitorView.h"
#import <Masonry.h>

@interface HMVisitorView ()

@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UIImageView *homeView;
@property(nonatomic,strong)UIImageView *coverView;
@property(nonatomic,strong)UILabel *messageLabel;
@property(nonatomic,strong)UIButton *registerBtn;
@property(nonatomic,strong)UIButton *loginBtn;

@end

@implementation HMVisitorView

#pragma mark - 提供视图的类方法

+(instancetype)visitorView
{
    return [[self alloc] init];
}

#pragma mark - 重写init方法

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setupUI];
        [self setupConstraints];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if(self = [super initWithCoder:aDecoder])
    {
        [self setupUI];
        [self setupConstraints];
    }
    return self;
}

#pragma mark - 添加子控件的方法

-(void)setupUI
{
    self.iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    [self addSubview:self.iconView];
    
    self.coverView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    [self addSubview:self.coverView];
    
    self.homeView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    [self addSubview:self.homeView];
    
    self.messageLabel = [[UILabel alloc] init];
    [self addSubview:self.messageLabel];
    self.messageLabel.numberOfLines = 0;
    self.messageLabel.textAlignment = NSTextAlignmentCenter;
    self.messageLabel.text = @"关注一些人,看看有神马惊喜!";
    
    self.registerBtn = [[UIButton alloc] init];
    [self addSubview:self.registerBtn];
    [self.registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    [self.registerBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    [self.registerBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.registerBtn addTarget:self action:@selector(visitorViewRegisterBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.loginBtn = [[UIButton alloc] init];
    [self addSubview:self.loginBtn];
    [self.loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
    [self.loginBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    [self.loginBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.loginBtn addTarget:self action:@selector(visitorViewLoginBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark - 添加约束的方法

-(void)setupConstraints
{
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-40);
    }];
    
    [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.bottom.equalTo(self.registerBtn.mas_bottom);
    }];
    
    [self.homeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView);
        make.centerY.equalTo(self.iconView);
    }];
    
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView);
        make.top.equalTo(self.iconView.mas_bottom).offset(16);
        make.width.mas_equalTo(250);
    }];
    
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.messageLabel);
        make.top.equalTo(self.messageLabel.mas_bottom).offset(8);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.registerBtn);
        make.right.equalTo(self.messageLabel);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
}

#pragma  mark - 改变访客视图的方法

-(void)changeVisitorWith:(NSString *)homeImageName message:(NSString *)message
{
    self.coverView.hidden = YES;
    self.iconView.hidden = YES;
    
    self.homeView.image = [UIImage imageNamed:homeImageName];
    self.messageLabel.text = message;
}

#pragma maek - 按钮监听方法
-(void)visitorViewRegisterBtnDidClick
{
    self.registrBtnBlock();
}

-(void)visitorViewLoginBtnDidClick
{
    self.loginBtnBlock();
}

@end











